#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>

int main(){

int val[4];
printf("4 Inputs - ");
scanf("%d", &val[0]);
scanf("%d", &val[1]);
scanf("%d", &val[2]);
scanf("%d", &val[3]);

int f_p[2];// file descriptor
pid_t fork_result;// data type for process id (pid_t)
int data;

if(pipe(f_p) == 0){  //successfull piping
fork_result = fork();
if(fork_result == -1){  //unsuccessfull forking
fprintf(stderr,"Fork Failure");
exit(EXIT_FAILURE);}

if(fork_result == 0){ //if process is child
printf("\nchild proc running\nProcess Id: %d", fork_result);
int temp = val[2] + val[3]; //C+D
data = write(f_p[1], &temp, sizeof(int));//passing address of temp, because you havce to 
exit(EXIT_SUCCESS);
}
else{// if process is parent
printf("\nparent proc running\nProcess Id: %d", fork_result);
val[0] += val[1];//val[0] stores A+B
data = read(f_p[0], &val[1], sizeof(int));
val[0] += val[1];//val[1] stores C+D
printf("\nTotal:\n%d\n",val[0]);}//,now val[0] stores (A+B) + (C+D)
}
exit(EXIT_SUCCESS);
}
